package com.educhains.web.util;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class FileUploadUtils {

    public static final List<String> ALLOW_TYPES = Arrays.asList(
            "image/jpg", "image/jpeg", "image/png", "image/gif"
//            //zip rar 7z
//            "application/octet-stream"
    );

    public static final List<String> ALLOW_TYPES_COURSE_TEACHERUPLOAD = Arrays.asList(
            //zip rar 7z
            "application/octet-stream"
    );


    public static String rename(String fileName) {
        int i = fileName.lastIndexOf(".");
        String str = fileName.substring(i);
        return new Date().getTime() + "" + new Random().nextInt(99999999) + str;
        //return StringUtils.generateRandomString(16);
    }

    public static boolean allowUpload(String postfix) {
        return ALLOW_TYPES.contains(postfix);
    }

    public static boolean allowUploadTeacherUpload(String postfix) {
        return ALLOW_TYPES_COURSE_TEACHERUPLOAD.contains(postfix);
    }
}
